<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

require_once IMMOPHP_ROOT_PATH. 'models'. DS .'contact.php';


class contact extends Controller
{
    public function index()
    {
        get_form_select_agence(array('' => $GLOBALS['lang']['Toute']));
        
        $GLOBALS['smarty']->assign( array(
                'agence_selected' => isset($_GET['agence']) ? $_GET['agence'] : ''));

        $GLOBALS['smarty']->assign('titre_site', $GLOBALS['setting']['titre_site'] .' - '. $GLOBALS['lang']['Contact']);

        return $GLOBALS['smarty']->fetch('contact.tpl');
     }

     public function send()
     {
        $email_destination = $GLOBALS['setting']['email_contact'];

        $this->getData();

        if( isset($this->data['send_email']) ):

            if( (ContactModels::alreadySend($this->data) == true) || (ContactModels::isSpam($this->data) == true) ):
                $this->printActionMessage($GLOBALS['lang']['Email_non_envoye_cause_deja_envoyer_ou_spam'], 'warning');
            else:

                if($this->data['agence'] != ''):
                    $email_destination = ContactModels::getEmailAgence($this->data['agence']);
                endif;

                if( ContactModels::sendEmail($this->data, $email_destination) ):
                    $this->printActionMessage($GLOBALS['lang']['Email_envoye']);
                else:
                    $this->printActionMessage($GLOBALS['lang']['Email_erreur_envoye'], 'warning');
                endif;

                ContactModels::sendDB($this->data);

            endif;

         endif;

        return $this->index();

     }
}

?>
